<?php

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use frontend\models\FenhuiForm;

$this->title = '申请分会';
$this->params['breadcrumbs'][] = $this->title;
?>
<style>
	.bo{background: #FFF;}
</style>
<section class="formbox">
	<form  action="<?= yii\helpers\Url::to(['member/apply_association']);?>" enctype="multipart/form-data" id="subform" method='post'>
		<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
		<div class="textlines">
			<ul>
				<li>
					<div class="boxline2" style="border: none;">
						<span>资质（如餐饮许可证）：</span>

						<div class="midinput" style="width: 2rem;">
							<span class="btn upload">-请添加-<input type="file" class="upload_pic" id="upload" name="fwdengjiimg" value="<?= $member['fwdengjiimg'] ?>" /></span>
						</div>
						<span class="xing">*</span>
						<?php
						if(!empty($cardf['newname']))
						{?>
							<img class="s_img" name="cardf" src="<?=Yii::$app->params['setshow']?><?= json_decode($member['fwdengjiimg'], true)['newname'];?>" />
						<?php } ?>
						<canvas class="all_cva" id="cvs"></canvas>
					</div>
				</li>
			</ul>
		</div>
		<input type="hidden" name="status"  value="10" />
		<input type="hidden" name="step"  value="4" />
		<div class="buzhou"><a href="<?= yii\helpers\Url::to(['member/apply_association', 'step' => 3])?>" class="upbtn">上一步</a><button class="nextbtn" type="submit">提交</button></div>

	</form>


</section>
<script type="text/javascript">
	$("#Text2").click(function (e) {
		var ths = this;
		calendar.show({
			id: this, ok: function () {
				//alert(ths.value);
			}
		});
	});
</script>
<script>
	//获取上传按钮
	var input1 = document.getElementById("upload");

	if(typeof FileReader==='undefined'){
		//result.innerHTML = "抱歉，你的浏览器不支持 FileReader";
		input1.setAttribute('disabled','disabled');
	}else{
		input1.addEventListener('change',readFile,false);
		/*input1.addEventListener('change',function (e){
		 console.log(this.files);//上传的文件列表
		 },false); */
	}
	function readFile(){
		var file = this.files[0];//获取上传文件列表中第一个文件
		if(!/image\/\w+/.test(file.type)){
			//图片文件的type值为image/png或image/jpg
			alert("文件必须为图片！");
			return false;
		}
		// console.log(file);
		var reader = new FileReader();//实例一个文件对象
		reader.readAsDataURL(file);//把上传的文件转换成url
		//当文件读取成功便可以调取上传的接口
		reader.onload = function(e){
			// console.log(this.result);//文件路径
			// console.log(e.target.result);//文件路径
			/*var data = e.target.result.split(',');
			 var tp = (file.type == 'image/png')? 'png': 'jpg';
			 var imgUrl = data[1];//图片的url，去掉(data:image/png;base64,)
			 //需要上传到服务器的在这里可以进行ajax请求
			 // console.log(imgUrl);
			 // 创建一个 Image 对象
			 var image = new Image();
			 // 创建一个 Image 对象
			 // image.src = imgUrl;
			 image.src = e.target.result;
			 image.onload = function(){
			 document.body.appendChild(image);
			 }*/

			var image = new Image();
			// 设置src属性
			image.src = e.target.result;
			var max=200;
			// 绑定load事件处理器，加载完成后执行，避免同步问题
			image.onload = function(){
				// 获取 canvas DOM 对象
				var canvas = document.getElementById("cvs");
				// 如果高度超标 宽度等比例缩放 *=
				/*if(image.height > max) {
				 image.width *= max / image.height;
				 image.height = max;
				 } */
				// 获取 canvas的 2d 环境对象,
				var ctx = canvas.getContext("2d");
				// canvas清屏
				ctx.clearRect(0, 0, canvas.width, canvas.height);
				// 重置canvas宽高
				/*canvas.width = image.width;
				 canvas.height = image.height;
				 if (canvas.width>max) {canvas.width = max;}*/
				// 将图像绘制到canvas上
				// ctx.drawImage(image, 0, 0, image.width, image.height);
				ctx.drawImage(image, 0, 0, 250, 150);
				// 注意，此时image没有加入到dom之中
			};
		}
	};
</script>




